package com.youth.controller;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.youth.entity.School;
import com.youth.service.ISchoolService;
import com.youth.service.impl.SchoolServiceImpl;
import com.youth.spring.contextholder.SpringContextHolder;

@Controller
@RequestMapping("")
public class SchoolController {
	
	Logger log = Logger.getLogger(SchoolController.class);
	
	@Autowired
	ISchoolService schoolService;
	
	@Autowired
	JdbcTemplate jdbcTemplate;
	
	@Value("#{prop['upload.path']}")
	private String uploadPath;
	
	@Value("#{prop['download.path']}")
	public String down;
	
	@RequestMapping("school")
	public String getSchool(Model model) {

		String s = jdbcTemplate.queryForObject("SELECT count(1) from t", String.class);
		System.out.println(s);
		
		System.out.println(uploadPath);
		log.info("method in getSchool ... ...");
		School sch = schoolService.getSchool();
		model.addAttribute("school", sch);
		return "school";
	}
	
	@RequestMapping("getBean")
	public void getBean(Model model) {
		ApplicationContext ac = SpringContextHolder.getApplicationContext();
		ISchoolService schoolService = ac.getBean(SchoolServiceImpl.class);
		School school = schoolService.getSchool();
		log.info(school.getName());
	}
	
}
